import { getResumes } from "~/server/database/services/resumeService";
import authMiddleware from "~/server/middleware/auth";

export default defineEventHandler(async (event) => {
  try {
    // 使用认证中间件获取用户信息
    await authMiddleware(event);
    
    // 从event.context中获取用户信息
    const user = event.context.user;
    const resumes = await getResumes(user.id);
    
    return {
      success: true,
      data: resumes
    };
  } catch (error: any) {
    console.error("获取简历列表失败:", error);
    if (error.statusCode) {
      throw error;
    }
    throw createError({
      statusCode: 500,
      statusMessage: "获取简历列表失败"
    });
  }
});
